package day10;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class XMLRead {
    public static void main(String[] args) {
        String path="E:\\java_workspace\\IdeaProjects\\kgc76\\javaadv\\src\\day10\\java76.xml";
        SAXReader reader=new SAXReader();
        Document doc=null;
        try {
             doc = reader.read(new File(path));
        } catch (DocumentException e) {
            e.printStackTrace();
            return;
        }
        System.out.println("根节点："+doc.getRootElement().getName());
        List<Element> list = doc.selectNodes("/javaclass/student");
        for(Element e:list){
            String no=e.attributeValue("no");
            String sex=e.attributeValue("sex");
            //Element name= (Element) e.selectNodes("name").get(0);
            Element name= (Element) e.selectSingleNode("name");
            String sname=name.getText();
            int age=Integer.parseInt(e.selectSingleNode("age").getText());
            String  phone= e.selectSingleNode("phone").getText();
            String  good= e.selectSingleNode("goodAt").getText().trim();
            System.out.println(no+","+sex+","+sname+","+age+","+phone+",good at:"+good);
        }
    }
}
